"""
AIPPT Data Models
"""
from typing import Optional, List, Dict, Any
from pydantic import BaseModel, Field


# ============================================================
# Task Models
# ============================================================

class TaskCreateRequest(BaseModel):
    """Request model for creating a PPT task"""
    type: int = Field(..., description="Task type: 1=smart generation, 2=upload file, 3=mind map, 4=word to ppt, 5=web link, 6=paste text, 7=markdown")
    content: Optional[str] = Field(None, description="Content based on task type")
    # files will be handled separately in multipart/form-data


class TaskCreateResponse(BaseModel):
    """Response model for task creation"""
    code: int
    message: str
    data: Optional[Dict[str, Any]] = None


# ============================================================
# Template Models
# ============================================================

class TemplateFilterOptions(BaseModel):
    """Template filter options"""
    themeColor: List[Dict[str, str]]
    category: List[Dict[str, str]]
    style: List[Dict[str, str]]
    layout: List[Dict[str, str]]


class Template(BaseModel):
    """Template model"""
    id: str
    name: Optional[str] = None
    type: int
    category: Optional[str] = None
    style: Optional[str] = None
    themeColor: Optional[str] = None
    lang: str = 'zh'
    animation: bool = False
    subject: Optional[str] = None
    coverUrl: Optional[str] = None
    fileUrl: Optional[str] = None
    pageCoverUrls: Optional[List[str]] = None


class TemplateListRequest(BaseModel):
    """Request model for listing templates"""
    current: int = Field(1, ge=1, description="Current page number")
    size: int = Field(10, ge=1, le=100, description="Page size")
    category: Optional[str] = None
    style: Optional[str] = None
    themeColor: Optional[str] = None
    layout: Optional[str] = None


class TemplateListResponse(BaseModel):
    """Response model for template list"""
    code: int
    message: str
    data: Optional[Dict[str, Any]] = None


class RandomTemplatesRequest(BaseModel):
    """Request model for getting random templates"""
    count: int = Field(5, ge=1, le=20, description="Number of templates to fetch")


# ============================================================
# Generation Models (V2)
# ============================================================

class GenerationOptions(BaseModel):
    """Generation options for V2 API"""
    audience: List[Dict[str, str]]
    lang: List[Dict[str, str]]
    pageCount: List[Dict[str, Any]]
    style: List[Dict[str, str]]


class GenerateContentRequest(BaseModel):
    """Request model for generating content"""
    taskId: str = Field(..., description="Task ID from createTask")
    isStream: bool = Field(False, description="Whether to use streaming response")
    prompt: Optional[str] = Field(None, description="Additional prompt for generation")
    templateId: Optional[str] = Field(None, description="Template ID to use")
    audience: Optional[str] = None
    lang: Optional[str] = 'zh'
    pageCount: Optional[int] = 10


class UpdateContentRequest(BaseModel):
    """Request model for updating content"""
    taskId: str = Field(..., description="Task ID")
    question: str = Field(..., description="User instruction to modify content")
    isStream: bool = Field(False, description="Whether to use streaming response")


class GeneratePPTRequest(BaseModel):
    """Request model for generating PPT file"""
    taskId: str = Field(..., description="Task ID")
    markdown: str = Field(..., description="Markdown outline and content")
    templateId: str = Field(..., description="Template ID to use")
    theme: Optional[str] = None
    author: Optional[str] = None
    title: Optional[str] = None


class GeneratePPTResponse(BaseModel):
    """Response model for PPT generation"""
    code: int
    message: str
    data: Optional[Dict[str, Any]] = None


# ============================================================
# PPT Management Models
# ============================================================

class PPTListRequest(BaseModel):
    """Request model for listing PPTs"""
    current: int = Field(1, ge=1, description="Current page number")
    size: int = Field(10, ge=1, le=100, description="Page size")


class DownloadPPTRequest(BaseModel):
    """Request model for downloading PPT"""
    id: str = Field(..., description="PPT ID")


# ============================================================
# Common Response Model
# ============================================================

class APIResponse(BaseModel):
    """Generic API response"""
    code: int
    message: str
    data: Optional[Any] = None
